package com.bosicloud.cmb.ibp.aws.adapter.component.notify;

import com.bosicloud.cmb.ibp.QueueNames;
import com.bosicloud.cmb.ibp.aws.adapter.component.notify.impl.NotificationImpl;
import com.bosicloud.cmb.ibp.aws.adapter.component.notify.impl.SubscriptionConfirmationImpl;
import com.bosicloud.cmb.ibp.commom.exception.BusinessException;
import org.springframework.cloud.aws.messaging.core.QueueMessagingTemplate;

/**
 * @author Jack Peng / ziliang.peng@bosicloud.com
 */
public class NotifyServiceFactory {

    /**
     * 消息类型
     */
    private enum Type {

        /**
         * 通知
         */
        Notification("Notification"),
        /**
         * 订阅确认
         */
        SubscriptionConfirmation("SubscriptionConfirmation");

        private String type;

        Type(String type) {
            this.type = type;
        }

        String type() {
            return this.type;
        }

        @Override
        public String toString() {
            return this.type;
        }
    }

    public static NotifyService getService(String type,
                                           String content,
                                           QueueMessagingTemplate template,
                                           QueueNames queueNames) {

        if(Type.SubscriptionConfirmation.type().equalsIgnoreCase(type.trim())) {
            return new SubscriptionConfirmationImpl(content);
        } else if(Type.Notification.type().equalsIgnoreCase(type.trim())) {
            return new NotificationImpl(content, template, queueNames);
        } else {
            throw new BusinessException("没有匹配的可处理的消息类型处理服务.");
        }

    }
}
